import request from '@/utils/request'
/**
 * 获取图形验证码
 * http://192.168.88.247:4999/web/#/14/48
 * @returns
 */
const VUE_APP_USER_URL = process.env.VUE_APP_USER_URL
export function getCodeImg (xzconfig) {
  return request({
    xzconfig,
    url: VUE_APP_USER_URL + '/api/v1/refresh_captcha',
    method: 'get'
  })
}

/**
 * 发送手机/邮箱验证码
 * http://showdoc.wisetimes.cn:4999/web/#/92/596
 * @returns
 */
export function sendSms (data, xzconfig) {
  return request({
    xzconfig,
    url: VUE_APP_USER_URL + '/api/v2/send_sms',
    method: 'post',
    data
  })
}

/**
 * 登录
 * http://192.168.88.247:4999/web/#/105/789 访问密码: RR8pUR67
 * @returns
 */
export function login (data, xzconfig) {
  return request({
    xzconfig,
    url: '/api/v2/member/login',
    method: 'post',
    data
  })
}

/**
 * 发送手机/邮箱验证码
 * http://192.168.88.247:4999/web/#/14/467
 * @returns
 */
export function getPartyParam (params) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/oath2_jsparam',
    method: 'get',
    params
  })
}

/**
 * 账号绑定第一步
 * http://192.168.88.247:4999/web/#/14/748
 * @returns
 */
export function bindAuth (data, xzconfig) {
  data.app_id = process.env.VUE_APP_ID
  return request({
    xzconfig,
    url: '/api/v1/bind/auth',
    method: 'post',
    data
  })
}

/**
 * 账号绑定第二步：合并账号
 * http://192.168.88.247:4999/web/#/14/748
 * @returns
 */
export function bindAuthMerge (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/bind/auth_merge',
    method: 'post',
    data
  })
}

/**
 * 绑定新手机号
 * http://192.168.88.247:4999/web/#/14/53
 * @returns
 */
export function changeBindPhone (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/user/phone',
    method: 'put',
    data
  })
}

/**
 * 注册
 * http://192.168.88.247:4999/web/#/14/46
 * @returns
 */
export function register (data, xzconfig) {
  return request({
    xzconfig,
    url: '/api/v1/logon',
    method: 'post',
    data
  })
}
export function userLogon (data, xzconfig) {
  return request({
    xzconfig,
    noMsg: true,
    url: VUE_APP_USER_URL + '/api/v1/user_logon',
    method: 'post',
    data
  })
}

/**
 * 检查用户是否已注册
 * http://192.168.88.247:4999/web/#/14/130
 * @returns
 */
export function checkUserIsExist (phonenumber, xzconfig) {
  return request({
    xzconfig,
    url: VUE_APP_USER_URL + '/api/v1/check_user',
    method: 'get',
    params: { phonenumber }
  })
}

/**
 * 注销登录
 * http://192.168.88.247:4999/web/#/14/49
 * @returns
 */
export function logout (params) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/logout',
    method: 'get',
    params
  })
}

/**
 * 解除绑定
 * http://192.168.88.247:4999/web/#/14/702
 * @returns
 */
export function oath2Unbind (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/oath2_unbind',
    method: 'delete',
    data
  })
}

/**
 * 获取用户信息
 * http://192.168.88.247:4999/web/#/14/702
 * @returns
 */
export function getUserInfo (isLogin) {
  return request({
    isLogin,
    url: VUE_APP_USER_URL + '/api/v1/user',
    method: 'get'
  })
}

/**
 * 检查手机验证码正确性
 * http://192.168.88.247:4999/web/#/14/129
 * @returns
 */
export function checkSms (params, xzconfig) {
  return request({
    xzconfig,
    url: VUE_APP_USER_URL + '/api/v1/check_sms',
    method: 'get',
    params
  })
}

/**
 * 更新用户密码
 * http://192.168.88.247:4999/web/#/14/51
 * @returns
 */
export function updatePwd (data, xzconfig) {
  return request({
    xzconfig,
    url: VUE_APP_USER_URL + '/api/v1/update_pwd',
    method: 'put',
    data
  })
}
/**
 * 更新用户密码
 * http://192.168.88.247:4999/web/#/14/51
 * @returns
 */
export function upEmailPwd (data, xzconfig) {
  return request({
    xzconfig,
    noMsg: true,
    url: VUE_APP_USER_URL + '/api/v1/update_emailPwd',
    method: 'put',
    data
  })
}
export function getSecurePub () {
  return request({
    headers: { Secure: 'HandShake' },
    url: '/api/v1/get_secure_pub',
    method: 'get'
  })
}
/**
 * 用户设备选择性踢出
 * http://192.168.88.247:4999/web/#/14/1178
 * @returns
 */
export function delDevice (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/device/multi_del',
    method: 'post',
    data
  })
}

/**
 * token授权码转换
 * http://192.168.88.247:4999/web/#/14/47
 * @returns
 */
export function refreshToken (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/exchanged_token',
    method: 'post',
    data
  })
}
/**
 * 创建公众号二维码
 * http://192.168.88.247:4999/web/#/217/1784
 * e8UsVRQ9
 * @returns
 */
export function createGzhQrcode (data) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/wx/qrcode/create',
    method: 'post',
    data
  })
}
/**
 * 轮询用户信息
 * http://192.168.88.247:4999/web/#/217/1925
 * e8UsVRQ9
 * @returns
 */
export function checkGzhLogin (params) {
  return request({
    noMsg: true,
    url: VUE_APP_USER_URL + '/api/v1/wx/user',
    method: 'get',
    params
  })
}
export function oauthUrl (params) {
  return request({
    url: VUE_APP_USER_URL + '/api/v1/oauth_url',
    method: 'get',
    params
  })
}
